const { salesmansAdd, salesmansRend, salesmansUpdata, salesmansModifyById, getSalesmansDeleteById, receiveSalesmanById } = require('../dao/salesmansDao')
//新增销售员
module.exports.salesmansAdd = async params => {

  const data = await salesmansAdd(params);
  if (data._id) {
    return {
      message: "销售员新增成功",
      status: 1
    }
  }
  else {
    return {
      message: "销售员新增失败",
      status: 0
    }
  }

}
//获取销售员
module.exports.salesmansRend = async (pramas) => {
  return await salesmansRend(pramas);

}

//销售员修改功能----通过_id获取待修改学生的信息
module.exports.salesmansUpdata = async (pramas) => {

  const re = await salesmansUpdata(pramas);

  if (re.length) {
    return {
      message: '数据获取成功',
      data: re[0],
      status: 1
    }
  }
  else {
    return {
      message: '数据获取失败',
      status: 0
    }
  }

}

//销售员修改功能----通过_id修改学生的信息
module.exports.salesmansModifyById = async (pramas) => {
  const re = await salesmansModifyById(pramas);
  if (re.nModified) {
    return {
      message: '数据修改成功',
      status: 1
    }
  }
  else {
    return {
      message: '数据修改失败',
      status: 0
    }
  }
}
//通过_id删除学生
module.exports.getSalesmansDeleteById = async params => {
  const data = await getSalesmansDeleteById(params);
  if (data.nModified > 0 || data.deletedCount > 0) {
    return {
      message: '删除成功',
      status: 1
    };
  } else {
    return {
      message: '删除失败',
      status: 0
    };
  }
}

//---------胡兴泽
//由id获取销售员
module.exports.receiveSalesmanById = async params => {
  const result = await receiveSalesmanById(params);
  return result
}